package anthology.daily_question._24_11;
//https://leetcode.cn/problems/alternating-groups-i/description/?envType=daily-question&envId=2024-11-26
public class _3206交替组1 {
    class Solution {
        public int numberOfAlternatingGroups(int[] colors) {
            int len = colors.length;
            int cut = 0;
            if(colors[len-1] != colors[0] && colors[0] != colors[1])
                cut++;
            for(int i=1; i<len; i++){
                if(i == len-1){
                    if(colors[i-1] != colors[i] && colors[i] != colors[0]){
                        cut++;
                    }
                }
                else if(colors[i-1] != colors[i] && colors[i] != colors[i+1]){
                    cut++;
                }
            }
            return cut;
        }
    }
    class Solution2 {
        public int numberOfAlternatingGroups(int[] colors) {
            int n = colors.length;
            int res = 0;
            for (int i = 0; i < n; i++) {
                if (colors[i] != colors[(i - 1 + n) % n] && colors[i] != colors[(i + 1) % n]) {
                    res += 1;
                }
            }
            return res;
        }
    }
}
